/**
 * @file     isUnique.js
 * @brief    [面试题 01.01. 判定字符是否唯一](https://leetcode-cn.com/problems/is-unique-lcci/)
 * @author   Zhu
 * @date     2022-03-18 17:45
 */

/**
 * @param {string} astr
 * @return {boolean}
 */
var isUnique = function (astr) {
    const map = {};
    for (const c of astr) {
        const v = map[c];
        if (v) {
            return false;
        }
        map[c] = 1;
    }
    return true;
};

/**
 * 位运算思路
 */
function isUnique(astr) {
    let res = 0;
    for (const char of astr) {
        const curCode = char.charCodeAt(0) - 97;
        const curBinary = 1 << curCode;
        if ((res & curBinary) !== 0) return false;
        else res |= curBinary;
    }

    return true;
}
